ROS2进阶:VS2019调试ROS2 | 您所在的位置:网站首页 › ubuntu2004 cuda100 › ROS2进阶:VS2019调试ROS2 |
Visual Studio有极其强大的调试功能,所以在windows上开发运行ROS程序时,可以尝试用VS2019的工具来进行调试。 (1)安装调试版ROS2要开发调试版程序,必须使用调试版本的ROS2,我使用的是galactic版本,因此到这里去下载, https://github.com/ros2/ros2/releases/download/release-galactic-20210716/ros2-galactic-20210616-windows-debug-amd64.zip Installing ROS 2 on Windows — ROS 2 Documentation: Galactic documentation C:\dev\ros2_galactic ----> 替换成 ---> C:\dbg\ros2_galactic 当然,相应的启动文件是: d:\>dbg.bat,内容如下, chcp 65001call C:\dbg\ros2_galactic\local_setup.bat(2)安装支持调试的python_d.exe如果你的python已经安装了调试库,这一步可以忽略。 如果你在前面的安装中没有enable debug,那么你会碰到这个问题 https://github.com/ros2/ros2/issues/525 解决办法是修改你的python安装,比如我用的python3.8.3,下载地址是 Python Release Python 3.8.3 | Python.org https://www.python.org/ftp/python/3.8.3/python-3.8.3-amd64.exe 然后勾选调试选项再安装就OK了, 首先,把examples从github上拉下来, cd examples_ws/srcgit clone --recursive -b galactic https://github.com/ros2/examples.git然后切换到examples_ws目录下, colcon build通常不会有太多的问题,就能顺利编译成功。 这里我们以publisher, subscriber为例进行讲解。官方的讲解在这里, Writing a simple publisher and subscriber (C++) — ROS 2 Documentation: Galactic documentation 关于如何查找package并枚举出package中的所有节点,请参考这个 ROS2进阶:如何查找特定的包(package)并列出包中所有节点(node)_高精度计算机视觉的博客 然后打开另一个控制窗口,启动subscriber, D:\ros2prj\examples_ws>call install/setup.bat"[rti_connext_dds_cmake_module][warning] RTI Connext DDS environment script not found (\resource\scripts\rtisetenv_x64Win64VS2017.bat). RTI Connext DDS will not be available at runtime, unless you already configured PATH manually.""[rti_connext_dds_cmake_module][warning] RTI Connext DDS environment script not found (\resource\scripts\rtisetenv_x64Win64VS2017.bat). RTI Connext DDS will not be available at runtime, unless you already configured PATH manually."D:\ros2prj\examples_ws>ros2 run examples_rclcpp_minimal_subscriber subscriber_member_function1648381040.630496 [0] 15480: using network interface 本地连接 (udp/10.88.0.6) selected arbitrarily from: 本地连接, 以太网 5[INFO] [1648381040.781102900] [minimal_subscriber]: I heard: 'Hello, world! 149'[INFO] [1648381041.289512100] [minimal_subscriber]: I heard: 'Hello, world! 150'[INFO] [1648381041.784118000] [minimal_subscriber]: I heard: 'Hello, world! 151'[INFO] [1648381042.280680300] [minimal_subscriber]: I heard: 'Hello, world! 152'[INFO] [1648381042.790295100] [minimal_subscriber]: I heard: 'Hello, world! 153'[INFO] [1648381043.287359800] [minimal_subscriber]: I heard: 'Hello, world! 154' 这样,publisher和subcriber通迅就完成了。 (5)VS2019单步调试通过前面的编译,这时候我们已经得到可以运行的VS2019项目了。但是,要独立运行这些项目,必须让系统能找到ROS的库文件,一个办法是把使用的库路径添加到系统环境变量中,例如, C:\dbg\ros2_galactic\bin 同样,如果发现其他找不到的库,也需要添加相应的环境变量。 需要注意的是,如果你同时在系统中安装有多个ROS库,那么在使用其他版本时就必须把这个路径从环境变量中删除,否则会出现库文件冲突的现象。 调试结果, 如果调试publisher,那就保持subscriber在cmd窗口运行;反过来,如果调试subscriber,就保持publisher在cmd窗口运行,这样,就可以清楚看到各个程序的运行状态了。 本文结束。 附:编译过程中碰到的问题 CMake Error in CMakeLists.txt: Imported target "rclcpp::rclcpp" includes non-existent path "C:/ci/ws/install/include" in its INTERFACE_INCLUDE_DIRECTORIES. Possible reasons include: * The path was deleted, renamed, or moved to another location. * An install or uninstall procedure did not complete successfully. * The installation package was faulty and references files it does not provide.解决办法, https://github.com/ros2/rclcpp/issues/1688 这里,这个C:\ci\ws\install\include是多余的,明显是忘记清除了。你可以找到那些CMakeLists.txt中相应的行,并将他们删除,另外一个简单的办法直接在以盘创建这么一个目录 C:\ci\ws\install\include 然后重新编译就没有问题了。 |
CopyRight 2018-2019 实验室设备网 版权所有 |